#include<bits/stdc++.h>
#define N 1100000
#define inf 1e9+7
#define eps 1e-7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline int read()
{
	char ch=0;
	int x=0,flag=1;
	while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch-'0');ch=getchar();}
	return x*flag;
}
struct edge{int to,nxt;}e[N*2];
int num,head[N];
inline void add(int x,int y){e[++num]={y,head[x]};head[x]=num;}
int times,id[N],lg[N],dep[N],f[N][22];
void dfs(int x,int fa)
{
	dep[x]=dep[fa]+1;f[++times][0]=x;id[x]=times;
	for(int i=head[x];i!=-1;i=e[i].nxt)
	{
		int to=e[i].to;
		if(to==fa)continue;
		dfs(to,x);f[++times][0]=x;
	}
}
int lca(int x,int y)
{
	if(id[x]>id[y])swap(x,y);
	int l=id[x],r=id[y],k=lg[r-l+1];
	x=f[l][k];y=f[r-(1<<k)+1][k];
	return (dep[x]<=dep[y])?x:y;
}
int main()
{
	int n=read();
	int m=read(),root=read();
	num=-1;memset(head,-1,sizeof(head));	
	for(int i=2;i<=n;i++)
	{
		int x=read(),y=read();
		add(x,y);add(y,x);
	}
	dfs(root,root);
	for(int i=1;i<=times;i++)lg[i]=lg[i-1]+((1<<(lg[i-1]+1))==i);
	for(int k=1;(1<<k)<=times;k++)
	for(int i=1;i+(1<<k)-1<=times;i++)
	{
		int x=f[i][k-1],y=f[i+(1<<(k-1))][k-1];
		f[i][k]=(dep[x]<=dep[y])?x:y;
	}
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		printf("%d\n",lca(x,y));
	}
	return 0;
}
